﻿﻿﻿﻿﻿﻿﻿﻿﻿﻿﻿function getBase(){
	//获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
    var curWwwPath = window.document.location.href;
    //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    //获取主机地址，如： http://localhost:8083
    var localhostPaht = curWwwPath.substring(0, pos);
    //获取带"/"的项目名，如：/uimcardprj
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);

	var basePath=localhostPaht
	return basePath;
}
var blueArr = ["03","04","09","10","14","15","20","25","26","31","36","37","41","42","47","48"]
var redArr = ["01","02","07","08","12","13","18","19","23","24","29","30","34","35","40","45","46"]
var greenArr = ["05","06","11","16","17","21","22","27","28","32","33","38","39","43","44","49"]
var error=[];   //报错页面的数组
function json2url(json) {
	var arr = [];
	for (var name in json) {
		arr.push(name + '=' + json[name]);
	}
	return arr.join('&');
}

/*$(window).bind("beforeunload",function(){
		alert("你确定要关闭此窗口吗？")
	})*/



function transDateLetter(dateSTR) {
	if(dateSTR ==  null){
		return
	}
	return dateSTR.replace(new RegExp("-","gm"),"/")
}

function dateToAddZero(num) {
    return num < 10 ? "0" + num : num
}

function getTwoDateMinus(date1, date2) {
	return date1.getTime() - date2.getTime()
}

function transNumToStr(s) {
	 var t
     if(s > -1){
         var hour = Math.floor(s/3600);
         var min = Math.floor(s/60) % 60;
         var sec = s % 60;
         if(hour < 10) {
             t = '0'+ hour + ":";
         } else {
             t = hour + ":";
         }

         if(min < 10){t += "0";}
         t += min + ":";
         if(sec < 10){t += "0";}
         t += sec
     }
     return t;
}

function transDateToStr(date) {
    var h = dateToAddZero(date.getHours()) + ':'
    var m = dateToAddZero(date.getMinutes()) + ':' 
    var s = dateToAddZero(date.getSeconds())
    return h + m + s
}

function ajax(json) {
	json = json || {};
	if (!json.url) return;
	json.data = json.data || {};
	json.type = json.type || 'get';

	var timer = null;

	if (window.XMLHttpRequest) {
		var oAjax = new XMLHttpRequest();
	} else {
		var oAjax = new ActiveXObject('Microsoft.XMLHTTP');
	}

	switch (json.type) {
		case 'get':
			oAjax.open('GET', json.url + '?' + json2url(json.data), true);
			oAjax.send();
			break;
		case 'post':
			oAjax.open('POST', json.url, true);
			oAjax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			oAjax.send(json2url(json.data));
			break;
	}

	oAjax.onreadystatechange = function() {
		if (oAjax.readyState == 4) {
			clearTimeout(timer);
			if (oAjax.status >= 200 && oAjax.status < 300 || oAjax.status == 304) {
				json.success && json.success(oAjax.responseText);
			} else {
				json.error && json.error(oAjax.status);
			}
		}
	};
}
function changImg1(){
	if($("#hhh1").attr("class").indexOf("glyphicon-menu-hamburger")!=-1){
		$("#hhh1").removeClass("glyphicon-menu-hamburger").addClass("glyphicon-th-large");
		$("#cai").removeClass("cai1");
		$("#cai").addClass("cai2");
	}else{
		$("#hhh1").removeClass("glyphicon-th-large").addClass("glyphicon-menu-hamburger");
		$("#cai").addClass("cai1");
		$("#cai").removeClass("cai2");
	}
	var height = $("#cai").find("li").eq(0)[0].clientHeight
	if ($("#hhh1").attr("class").indexOf("glyphicon-menu-hamburger")!=-1) {
		height += 1
	}
	$("[data-cname='xg6hc']").css("height", height + "px")
}


function changImg(){
	if($("#hhh").attr("class").indexOf("glyphicon-menu-hamburger")!=-1){
		$("#hhh").removeClass("glyphicon-menu-hamburger").addClass("glyphicon-th-large");
		$("#cai").removeClass("cai1");
		$("#cai").addClass("cai2");
	}else{
		$("#hhh").removeClass("glyphicon-th-large").addClass("glyphicon-menu-hamburger");
		$("#cai").addClass("cai1");
		$("#cai").removeClass("cai2");
	}
	var height = $("#cai").find("li").eq(0)[0].clientHeight
	if ($("#hhh").attr("class").indexOf("glyphicon-menu-hamburger")!=-1) {
		height += 1
	}
	$("[data-cname='xg6hc']").css("height", height + "px")
}


function alertme(str){
	$("body").append("<div id='alertme' style='text-align:center;'><div style='position: fixed;z-index:9999999999;left:0;top:0;background: rgba(20,20,20,0.3);width:100%;height:100%;'></div><div style='position: fixed;z-index:10000000000;width:80vw;background: white;bottom:100px;margin:10vw;border-radius:10px;height: 150px;'>"
			+"<div style='font-size: 14px;height:100px; line-height:100px;width:100%;'>"+str+"</div><div style='position: absolute;bottom: 0px;width: 100%;height: 50px; '>"
			+"<a onclick='removealertme()' style='width: 100%;float: left;height:100%;line-height:50px;border: 0;color:black; border-radius:0 0 20px 20px;font-size: 20px;outline: none;border-top:1px solid gray;'>确　　定</a></div></div>");
	$('.alertme').show(500);
}
function removealertme(){$('#alertme div:nth-child(2)').fadeOut(300);setTimeout(function(){$('#alertme').remove();},320);}


function promptme(str1,str2){
	$("body").append("<div class='promptme' style='background:rgba(200,200,200,0.9);position: fixed;width: 300px;bottom:0;left:0; right:0; top:0; margin:auto;display:none;"
			+"height: 150px; border-radius: 10px;'></div>"
			+"<div class='promptme' style='color: black;width: 300px; height: 150px; border-radius: 20px;display:none;"
			+"text-align:center;position: fixed;bottom:0;left:0; right:0; top:0; margin: auto;'>"
			+"<div style='font-size: 16px;height:20px; line-height:20px;width:100%;padding:10px;text-align:left;'>"+str1+"</div>"
			+"<input placeholder="+str2+" style='width:96%;border:1 solid white;background:#E5E5E5;padding:5px;margin:2%;margin-top:25px;border-radius:5px;' />"
			+"<div style='position: absolute;bottom: 0px;width: 100%;height: 50px; '>"
			+"<a onclick='okpromptme()' style='width: 50%;float: left;height:100%;line-height:50px;border: 0;color:black;border-right:1px solid white;"
			+"border-radius:0 0 0 20px;font-size: 20px;outline: none;border-top:1px solid white;'>确　　定</a>"
			+"<a onclick='removepromptme()' style='width: 50%;float: left;height:100%;line-height:50px;border: 0;color:black;border-left:1px solid white;"
			+"border-radius:0 0 20px 0;font-size: 20px;outline: none;border-top:1px solid white;'>取　　消</a>"
			+"</div></div>");
	$('.promptme').fadeIn(300);
}
function removepromptme(){$('.promptme').fadeOut(300);setTimeout(function(){$('.promptme').remove();},300);}
function okpromptme(){removepromptme();return 20;}



function back() {
	window.history.back(-1);
}	

function backPage(){
	if(save==""){
		save.push("sy")
	}
	if(save[save.length-1]=="bjl"){
		BG_SOUND.stop()
	}
	if(save[save.length-1]=="sy"){    //如果回到了首页，则只保留一个sy
		save=[];
		save.push("sy")
	}
	console.log(save)
	$(".foot").show()   //显示底部栏
	windowChange=true;
	var newData=localStorage.getItem(save[save.length-1])   //获取页面的数据
	page=save[save.length-1]
	if(error.indexOf(page)!=-1){
		maintenance()
		return;
	}
	
	if(page=="lotter"){  
		clearInterval(timer)
		bindsetLotterData(caizhong_cname)
	}else{
		 if(newData == undefined || newData==""){ //判断页面数据是否为空，如果为空，则要
			 setMainTitle(page)
		}else{  
			 $("#xfm").html(newData)
		}
		 clearInterval(timer)
	}
	
	if(save[save.length-1]=="login"){
		$(".dhssdhgbsdfg a").removeClass("active")
		$(".dhssdhgbsdfg").find(".sy").addClass("active")
	}else{
		$(".dhssdhgbsdfg a").removeClass("active")
		$(".dhssdhgbsdfg").find("."+page).addClass("active")
	}
	save.pop()    //删除数组的最后一个
}

function login(){
	ajax({
		url:'/u/login.do',
		type:'post',
		data:{
			name:$("#name").val(),
			pass:$("#pass").val(),
			code:$("#code").val()
		},
		success:function(data){
			if(data==60){
				pagePreserve()
				return;
			}
			var json=eval('('+data+')');
			if(json.message==4){
				//登录成功
				userLoginData()
				$(".foot").hide()
				$(".kd-loading").show();
				$("#xfm").hide();
				page="sy" 
				save.push("sy")
				$("#xfm").html("")
				$(".dhssdhgbsdfg a").removeClass("active")
				$(".dhssdhgbsdfg").find("."+page).addClass("active")
				bindSetData(page)
				reconnect();
			}else if(json.message==1){
				//验证码输入错误  请重新输入
				showNormalNoticeModal("#div-i-noticeGenDan", "提示：", "验证码输入错误请重新输入")
			}else if(json.message == 0){
				//请重新刷新验证码
				showNormalNoticeModal("#div-i-noticeGenDan", "提示：", "请重新刷新验证码")
			}else if(json.message == 2){
				//账号已被禁用 请联系客服人员
				showNormalNoticeModal("#div-i-noticeGenDan", "提示：", "账号已被禁用请联系客服人员")
			}else if(json.message == 3){
				//该ip被禁用，请更换ip重新登录
				showNormalNoticeModal("#div-i-noticeGenDan", "提示：", "该ip被禁用请更换ip重新登录")
			}else if(json.message == 5){
				//账号或密码错误请重新输入
				showNormalNoticeModal("#div-i-noticeGenDan", "提示：", "账号或密码错误请重新输入")
			}
		}
	});
}
function fenli(str){
	var num="";
	var st="";
	var color="puker";
	if(str.indexOf("fangp")!=-1){
		st="["
		num=str.replace("fangp","");
	}
	if(str.indexOf("meih")!=-1){
		st="]"
		num=str.replace("meih","");
		color="pukeb";
	}
	if(str.indexOf("heit")!=-1){
		st="}"
		num=str.replace("heit","");
		color="pukeb";
	}
	if(str.indexOf("hongt")!=-1){
		st="{"
		num=str.replace("hongt","");
	}
	if(num==10)num="="
	if(num==1)num="a"
	return "<span class='"+color+"'>"+st+num+" </span>";
}
Date.prototype.format = function(fmt) { 
    var o = { 
       "M+" : this.getMonth()+1,                 //月份 
       "d+" : this.getDate(),                    //日 
       "h+" : this.getHours(),                   //小时 
       "m+" : this.getMinutes(),                 //分 
       "s+" : this.getSeconds(),                 //秒 
       "q+" : Math.floor((this.getMonth()+3)/3), //季度 
       "S"  : this.getMilliseconds()             //毫秒 
   }; 
   if(/(y+)/.test(fmt)) {
           fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
   }
    for(var k in o) {
       if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }
   return fmt; 
}       

function bu0(str){
	str=Number(str);
	if(str>=0&&str<10){
		return "0"+str;
	}
	return str;
}

function clear1() {
	$(".act").removeClass("act");
	$("input").not(".bbbbb").val("");
}


function jisuan(){
	if(MAX_PL==0){
		MAX_PL=$("#maxpl").text();
	}
	var fanli=1;
	$("#maxpl").text(Subtr(MAX_PL,accDiv(fanli,100)));
	$("#fanli").text(fanli/10);
	var heji=accMul($("#zhusu").text(),$("#danzhu").val());
	var makzj=accMul($("#maxpl").text(),$("#danzhu").val());
	$("#heji").text(heji);
	$("#makzj").text(makzj);
	FAN_LI=fanli;
}
//除法
function accDiv(arg1, arg2) {
	var t1 = 0,
		t2 = 0,
		r1, r2;
	try {
		t1 = arg1.toString().split(".")[1].length
	} catch (e) {}
	try {
		t2 = arg2.toString().split(".")[1].length
	} catch (e) {}
	with(Math) {
		r1 = Number(arg1.toString().replace(".", ""))
		r2 = Number(arg2.toString().replace(".", ""))
		return accMul((r1 / r2), pow(10, t2 - t1));
	}
}
//乘法 
function accMul(arg1, arg2) {
	var m = 0,
		s1 = arg1.toString(),
		s2 = arg2.toString();
	try {
		m += s1.split(".")[1].length
	} catch (e) {}
	try {
		m += s2.split(".")[1].length
	} catch (e) {}
	return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
}
//加法  
function accAdd(arg1, arg2) {
	var r1, r2, m;
	try {
		r1 = arg1.toString().split(".")[1].length
	} catch (e) {
		r1 = 0
	}
	try {
		r2 = arg2.toString().split(".")[1].length
	} catch (e) {
		r2 = 0
	}
	m = Math.pow(10, Math.max(r1, r2))
	return (arg1 * m + arg2 * m) / m
}
//减法  
function Subtr(arg1, arg2) {
	var r1, r2, m, n;
	try {
		r1 = arg1.toString().split(".")[1].length
	} catch (e) {
		r1 = 0
	}
	try {
		r2 = arg2.toString().split(".")[1].length
	} catch (e) {
		r2 = 0
	}
	m = Math.pow(10, Math.max(r1, r2));
	n = (r1 >= r2) ? r1 : r2;
	return ((arg1 * m - arg2 * m) / m).toFixed(n);
}
function submit(){
	if($(".hemei").attr("class").indexOf("hidden")==-1){
		var zcount=$(".fs").val();
		var price=$(".meifen").text();
		var profit=$(".tc").val();
		var rcount=$(".rg").val();
		var bcount=$(".bd").val();
		ajax({
			url:'/order/submit.do',
			type:'post',
			data:{rebate:$("#fanli").text(),acount:$("#heji").text(),id:$("#orderid").text(),lottermoney:$("#danzhu").val(),zcount:zcount,price:price,profit:profit,rcount:rcount,bcount:bcount,state:0},
			success:function(data){
				var json = eval('(' + data + ')');
				if(json.data==1){
					$(".queren").text("下注成功");
					$(".zdsd").addClass("hidden");
					clear1();
				}
			}
		});
		
	}else{
		ajax({
			url:'/order/submit.do',
			type:'post',
			data:{rebate:$("#fanli").text(),acount:$("#heji").text(),id:$("#orderid").text(),lottermoney:$("#danzhu").val()},
			success:function(data){
				if(data==60){
					pagePreserve()
					return;
				}
				var json = eval('(' + data + ')');
				if(json.data==1){
					$(".queren").text("下注成功");
					$(".zdsd").addClass("hidden");
					clear1();
				}
			}
		});
	}
	
	/*ajax({
		url:'/cp/order/submit.do',
		type:'post',
		data:{rebate:$("#fanli").text(),acount:$("#heji").text(),id:$("#orderid").text(),lottermoney:$("#danzhu").val()},
		success:function(data){
			var json = doeval('(' + data + ')');
			if(json.data==1){
				$(".queren").text("下注成功");
				$(".zdsd").addClass("hidden");
				clear1();
			}
		}
	});*/
}

function set_focus()
{
    el=$(".div-c-editArea")
    el=el[0];  //jquery 对象转dom对象
    el.focus();
    if($.support.msie)
    {
        var range = document.selection.createRange();
        this.last = range;
        range.moveToElementText(el);
        range.select();
        document.selection.empty(); //取消选中
    }
    else
    {
        var range = document.createRange();
        range.selectNodeContents(el);
        range.collapse(false);
        var sel = window.getSelection();
        sel.removeAllRanges();
        sel.addRange(range);
    }
}

var timerId = null 
var interval	
var CURRENT_TYPE
var EVENT_OBJECT_CURRENT = {
		"computer": {touchStartEvent: "click", touchEvent: "click"},
		"mobile": {touchStartEvent: "touchstart", touchEvent: "touchend"},
	}

var checkEditorHeight = function(height) {
	var currentHeight = document.querySelector(".div-c-editArea").clientHeight
	if (currentHeight != height) {
		$(".editarea-wrapper").removeClass("editarea-wrapper-active")
	} else {
		$(".editarea-wrapper").addClass("editarea-wrapper-active")
	}
}

var bindEditContentEvent = function(callback) {
	if (window.ontouchend === undefined) {
		CURRENT_TYPE = "computer"
	}
	else {
		CURRENT_TYPE = "mobile"
	}
/*	var DIV_START_HEIGHT = document.querySelector(".div-c-editArea").clientHeight*/
	$("#svg-i-toggleExtraTool").on(EVENT_OBJECT_CURRENT[CURRENT_TYPE].touchEvent, function(event) {
		$(".div-c-extraTool").toggleClass("div-c-extraTool-active")
		if($(".div-c-extraTool").hasClass("div-c-extraTool-active")){
			$(".help").css("height","50px")
		}else{
			$(".help").css("height","0px")
		}
		setTimeout(function() {
			$(".div-c-editArea")[0].blur()
			var extraHeight = document.querySelector(".div-c-extraTool").clientHeight
			window.scrollTo(0, document.body.clientHeight + extraHeight)				
		}, 50)
		//svg-i-toggleExtraTool
	})
	$(".w-e-menu").on(EVENT_OBJECT_CURRENT[CURRENT_TYPE].touchEvent, function(event) {
		event.preventDefault()
		$(".w-e-panel-container").toggleClass("w-e-panel-container-active")
		//$("#svg-i-toggleExtraTool")[0].classList.toggle("w-e-menu-active")
		var svgTool = document.querySelector("#svg-i-toggleExtraTool")
		if (svgTool.classList.contains("w-e-menu-active")) {
			svgTool.classList.remove("w-e-menu-active")
		} else {
			svgTool.classList.add("w-e-menu-active")
		}
/*		if (!$(".w-e-panel-container").hasClass("w-e-panel-container-active")) {
			$(".sendMessageWrapper").removeClass("sendMessageWrapper-fix")
		} else {
			$(".sendMessageWrapper").addClass("sendMessageWrapper-fix")
		}*/
		setTimeout(function() {
			$(".div-c-editArea")[0].blur()
			var extraHeight = document.querySelector(".div-c-extraTool").clientHeight
			var extraEmojiHeight = document.querySelector(".w-e-panel-container").clientHeight 
			window.scrollTo(0, document.body.clientHeight + extraEmojiHeight)				
		}, 50)		
	})
	$(".w-e-panel-tab-title .w-e-item").on(EVENT_OBJECT_CURRENT[CURRENT_TYPE].touchEvent, function(event) {
		event.preventDefault()
		var item = $(this)
		var dataIndex = item[0].dataset.index
		$(".w-e-active").removeClass("w-e-active");
		item.addClass("w-e-active")
		$(".w-e-emoticon-container-active").removeClass("w-e-emoticon-container-active")
		$("#w-e-emoticon-container" + dataIndex).addClass("w-e-emoticon-container-active")
	})
	/*$(".w-e-emoticon-container .w-e-item").on(EVENT_OBJECT_CURRENT[CURRENT_TYPE].touchEvent, function(event) {
		event.preventDefault()
		var currentItem = $(this)
		if (currentItem[0].tagName != "SPAN") {
			currentItem = currentItem[0].closest(".w-e-item")
		}
		var value = currentItem.html().trim()
		if ($(".div-c-editArea").html().trim() == "") {
			$(".div-c-editArea").html(value)
		} else {
			$(".div-c-editArea").append(value)
		}
		set_focus()
		checkEditorHeight(DIV_START_HEIGHT)
	})*/
	$(".div-c-editArea").on("input", function(event) {
		var startHeight = event.currentTarget.clientHeight
	})
	$(".div-c-editArea").on("focus", function(event) {
		var explorer = navigator.userAgent
		if(explorer.indexOf("UCBrowser") >= 0){
			var cnt = 0
			timerId = setInterval( function() {
			    if (cnt < 3) {
			      cnt++
			    } else {
			      clearInterval(timerId)
			      timerId = null
			      return
			    }
			   document.body.scrollTop = document.body.scrollHeight
			  window.scrollTo(0,document.body.scrollHeight)/*document.body.scrollHeight*/
		  }, 100)				
		}
	})		
	$(".div-c-editArea").on("blur", function(event) {
	    if (timerId) {
		    clearInterval(timerId);
		    timerId = null;
		}
	})		
}

function isCurrentNumber (str) {
	if (!isNumber(str)) {
		return false
	}
	if (Number(str) <= 0) {
		return false
	}
	return true
}

function isNumber(str) 
{
   var  re=/^\d+(?:\.\d{1,4})?$/;
   return re.test(str)
}

var showNoticeModal = function(innerHTML) {
	var nocticeElement = document.querySelector("#noticeModal")
	var mobody = nocticeElement.querySelector(".modal-body")
	mobody.innerHTML = innerHTML
	$('#noticeModal').modal('show')
}

function GetQueryString(name)
{
　　var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
　　var r = window.location.search.substr(1).match(reg);
　　if(r!=null)return unescape(r[2]);
   return null;
}

var showFakeModal = function(elee) {
	$(elee).css("display", "flex")
	setTimeout(function() {
		$(elee).addClass("in")
	}, 200)
}



var showNormalNoticeModal = function(elee, title, content) {
	if ($(elee).attr("data-lock") === "true") {
		return
	}
	$(elee).attr("data-lock", "true")
	$(elee).find(".fakemodal-title").html(title)
	$(elee).find(".fakemodal-content").html(content)
	$(elee).css("display", "flex")
	setTimeout(function() {
		$(elee).addClass("in")
	}, 100)
}

/*<div class="modal-div-fakeModal" id="div-i-noticeGenDan">
<div class="div-c-modalContent">
	<h3 class="fakemodal-title"></h3>
	<div class="fakemodal-content"></div>
	<div class="fakemodal-btnsGroup"><button class="btn btn-default btn-class-closeFakeModal">关闭</button></div>
</div>
</div>	*/

var showNoResultNoticeModal = function(elee, title, normalText, linkText) {
	showNormalNoticeModal(elee, title, "<span>" + normalText + "</span><br><a class='a-c-noresultLinkStyle'>" + linkText + "</a>")
	$("#div-i-noticeGenDan").on("click",".a-c-noresultLinkStyle",function(){
		$("#div-i-noticeGenDan").removeClass("in")
		 bindSetData("gc")
	})
}

//<div class="modal-div-fakeModal" id="div-i-noticeBankCard">
//<div class="div-c-modalContent">
//	<h3 class="fakemodal-title">提示</h3>
//	<div class="fakemodal-content">你还未绑定银行卡帐号,绑定后可获得礼金</div>
//	<div class="fakemodal-btnsGroup"><button class="btn btn-default btn-class-closeFakeModal">关闭</button></div>
//</div>
//</div>

//showFakeModal("#div-i-noticeBankCard")

var bindAllCloseFakeModalBtns = function() {
	$(document).ready(function(){
		$(".modal-div-fakeModal").on(getNormalClickEvent(), ".btn-class-closeFakeModal", function(event) {
			$(event.target).closest(".modal-div-fakeModal").removeClass("in")
		})
		$(".modal-div-fakeModal").on(getNormalClickEvent(), ".div-c-modalContent", function(event) {
			event.stopPropagation()
		})
		$(".modal-div-fakeModal").on(getNormalClickEvent(), function(event) {
			var $self = $(event.currentTarget)
			if ($self.hasClass("important")) {
				return
			}
			$self.removeClass("in")
		})	
		$(".modal-div-fakeModal").on("transitionend", function(e) {
			var $self = $(e.currentTarget)
			if (!$self.hasClass("in")) {
				$self.css("display", "none")
				$self.attr("data-lock", "false")
			}
		})
		$(".modal-div-fakeModal").on("touchmove", function(e) {
			var $self = $(e.currentTarget)
			if ($self.hasClass("in")) {
				e.preventDefault()
				return false
			}
		})		
	})
}



var setContentBodyHeight = function() {
	 var allHeight = document.documentElement.clientHeight
	 var headerHeight = $(".bg-theme").height()
	 var footerHeight = $(".foot").height() 
	 var restHeight = allHeight - headerHeight - footerHeight
	 document.querySelector(".content-middle-body").style.height = restHeight + "px"	 //
}

var fixHeadAndFoot = function() {
	var explorer = navigator.userAgent
	if(explorer.indexOf("UCBrowser") >= 0){
		$(".top").css("position", "absolute")
		$(".foot").css("position", "absolute")
	}	
}

var fixEditHeadAndFoot = function(top, foot) {
	var explorer = navigator.userAgent
	if(explorer.indexOf("UCBrowser") >= 0){
		$(top).css("position", "absolute")
		$(foot).css("position", "absolute")
	}	
}

/*<!-- 提醒模态框（Modal） -->

<div class="modal fade" id="noticeModal" tabindex="-1" role="dialog" aria-labelledby="noticeModal" aria-hidden="true">
    <div class="modal-dialog class-fake-alert">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body" ></div>
            <div class="modal-footer">	      
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>   	
<!-- 提醒模态框（Modal）结束 -->*/

var showNoticeModal = function(innerHTML) {
	var nocticeElement = document.querySelector("#noticeModal")
	var mobody = nocticeElement.querySelector(".modal-body")
	mobody.innerHTML = innerHTML
	$('#noticeModal').modal('show')
}

var vaildPassWord = "1234567890qwertyuioplkjhgfdsazxcvbnm"
var checkPassWordValid = function(str) {
	if (!str) {
		return "无效的密码格式"
	}
	if (str.length < 6 || str.length > 15) {
		return "密码的长度必须大于6位且小于15位"
	}
	var flag = true
	for (var i = 0; i < str.length; i++) {
		if (!vaildPassWord.includes(str[i])) {
			flag = false
			break
		}
	}
	if (!flag) {
		return "密码只能包含数字或字母"
	}
	return "ok"
}

function isValidIP(ip) {
    var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
    return reg.test(ip);
} 

function initAllTable() {
	$(".table-normal-datatables").DataTable({
      // "bPaginate": true,
      "bLengthChange": true,      
      "bSort": false,
      // "bInfo": true,
      "bAutoWidth": false,
//	         "bServerSide":true,
      'aLengthMenu':[ 10, 20],
       "searching": false,
       "dom": "ftp",
//	    "searching": true,l
       "language": {//语言设置  
            "lengthMenu": "每页显示 _MENU_ 条记录",     
            "zeroRecords": "没有检索到数据",     
            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",     
            "info": "没有数据",     
            "oPaginate": {     
                "sFirst": "首页",     
                "sPrevious": "前一页",     
                "sNext": "后一页",     
                "sLast": "尾页"    
          	},
            "search":"搜索:",
            "infoFiltered":   "(从  _MAX_ 记录中搜索出结果)",
            "infoEmpty":      "没有找到匹配的信息",
         },	       
    })
}

function changeUserState($node) {
	if ($node.hasClass("btn-primary")) {
		$node.removeClass("btn-primary").addClass("btn-success").text("启用")
	}
	else {
		$node.removeClass("btn-success").addClass("btn-primary").text("禁用")
	}	
}

//滚动到底部
function scrollToEnd(){

document.body.scrollTop = document.body.scrollHeight;
}

var bindSendMessageWrapperEvent = function(callback) {
	$(document).ready(function(){
		var scrollHeight;
		document.querySelector(".div-c-editArea").addEventListener("focus", function(event) {
			scrollHeight=setInterval(function() {
			/*	callback()*/
				var allHeight = document.documentElement.clientHeight
				var toolHeight = document.querySelector(".div-c-extraTool").clientHeight
				var emojiHeight = document.querySelector(".w-e-panel-container").clientHeight
				var resultHeight = allHeight + toolHeight + emojiHeight
				/*window.scrollTo(0, 80)*/
			}, 100)
		})
		document.querySelector(".div-c-editArea").addEventListener("blur",function(){
			clearInterval(scrollHeight)
		})
	})
}

function isMobile() {
    return navigator.userAgent.match(/(|mobile|iphone|ipad|ipod|ios|android|blackberry|iemobile|mqqbrowser|juc|fennec|wosbrowser|browserng|Webos|symbian|windows phone)/i);
}/**/

var GLOBAL_KEYS = isMobile() ? "mobile" : "pc"

var GLOBAL_EVENT_OBJECT = {
	"pc": {"normalClick": "click", "endClick": "click",},
	"mobile": {"normalClick": "touchstart", "endClick": "touchend",},
}

var getNormalClickEvent = function() {
	return GLOBAL_EVENT_OBJECT[GLOBAL_KEYS].normalClick
}

var getEndClickEvent = function() {
	return GLOBAL_EVENT_OBJECT[GLOBAL_KEYS].endClick	
}

 

var bindJinYongQiYongSwitch = function(tableSelector, path, stateValue) {
  	$(tableSelector).on("switchChange.bootstrapSwitch", ".input-c-mySwitch", function(e, state) {
		var $Event = $(event.target)
		var $parent = $Event.closest("tr")
		var idValue = $parent.find(".id-edit-td").text()
		var status = state ? "1" : "0"
		var urlPath = path
		var newRequest = {
			url: urlPath,
			type: "post",
			data: {id: idValue},
			success: function(data) {
				$(e.currentTarget).bootstrapSwitch("state", state, true)
			},
			error: function(status) {
				showNoticeModal("修改状态失败，请稍后重试")
				$(e.currentTarget).bootstrapSwitch("state", !state, true)
			}
		}
		newRequest.data[stateValue] = status
		ajax(newRequest)
    })	
}

var bindSystemSwitch = function(tableSelector,className, path, stateValue) {
  	$(tableSelector).on("switchChange.bootstrapSwitch", className, function(e, state) {
		var $Event = $(event.target)
		var $parent = $Event.closest("tr")
		var idValue = $parent.find(".id-edit-td").text()
		var status = state ? "1" : "0"
		var urlPath = path
		var newRequest = {
			url: urlPath,
			type: "post",
			data: {id: idValue},
			success: function(data) {
				$(e.currentTarget).bootstrapSwitch("state", state, true)
			},
			error: function(status) {
				showNoticeModal("修改状态失败，请稍后重试")
				$(e.currentTarget).bootstrapSwitch("state", !state, true)
			}
		}
		newRequest.data[stateValue] = status
		ajax(newRequest)
    })	
}


var IS_USER_MOVE = false

var bindCollapseItemEvent = function() {
	$(".div-c-collapseTitle").on("touchstart",function(){
		IS_USER_MOVE = false
	})
	$(".div-c-collapseTitle").on("touchmove",function(){
		IS_USER_MOVE = true
	})	
	$(".div-c-collapseTitle").on(getEndClickEvent(), function(event) {
		if (IS_USER_MOVE && isMobile()) {
			return
		}		
		$(event.currentTarget).parent().toggleClass("active")
	})
}

var lastTouchEnd = 0

var stopUserScaleScreenIOS = function() {
	if (GLOBAL_KEYS == "pc") {
		return
	}	
	/*document.documentElement.addEventListener('touchstart', function (event) {
		  if (event.touches.length > 1) {
		    event.preventDefault();
		  }
		}, false);*/
	document.documentElement.addEventListener('touchend', function (event) {
	  var now = Date.now();
	  if (now - lastTouchEnd <= 300) {
	    event.preventDefault();
	  }
	  lastTouchEnd = now;
	}, false);	
}

var checkValueIsNumber = function(string) {
	var stringValue = Number(string)
	if (isNaN(stringValue) || stringValue == null || stringValue == undefined) {
		return false
	}
	if (stringValue == "") {
		return false
	}
	for (var i = 0; i < stringValue.length; i++) {
		var letter = stringValue[i]
		if (!numberString.includes(letter)) {
			return false
		}
	}
	if (stringValue.length > 1) {
		if (stringValue[0] == "0") {
			return false
		}
	}
	if (stringValue < 0) {
		return false
	}
	return true
}

function jianrong() {
	var htmlSelector = document.documentElement
	var width = htmlSelector.clientWidth
	if (width > 400) {
		width = 400
	}
	var fSize = width / 7.5
	htmlSelector.style.fontSize = String(fSize) + "px"
	htmlSelector.dataset.fontrem = fSize.toFixed(2)
}

function bindLockUnlockBtns(datatable, ajaxUrl) {
	$(datatable).on("click", ".btn-c-suoding", function(e) {
		var $self = $(e.currentTarget)
		var $parent = $self.closest("tr")
		var type = $self.attr("data-type")
		ajax({
			url: ajaxUrl,
			type: "post",
			data: {state: type == "unlock" ? "处理中" : "未处理", caozuo: type == "unlock" ? "取消锁定" : "锁定", id: $parent.find(".id-td").text()},
			success: function(data) {
				if (type == "unlock") {
					$self.text("取消锁定")
				    $self.attr("data-type", "lock")
				    $self.next().addClass("active")
				}
				else if (type == "lock") {
					$self.text("锁定")
				    $self.attr("data-type", "unlock")
				    $self.next().removeClass("active")				
				}	
				/*$(datatable).DataTable().ajax.reload()*/
			},
			error: function(status) {
				showNoticeModal('网络异常')
			}
		})
	})	
}

/*function getXiaZhuUrl() {
	 bindSetData("gc")
}*/

var appendNumberToPage = function() {
	var html = 
		"<input type='text' class='class-input-pageNumberTwo input-xs' />"+
			"<button class='class-span-searchBtnTwo btn btn-default'>跳转</button>"
		var searchDiv = document.querySelectorAll(".tableSearch")
		for (var i = 0; i < searchDiv.length; i++) {
			var item = searchDiv[i]
			item.insertAdjacentHTML("beforeend", html)
		}
	}	


/*	假分页根据输入页数跳转到指定页 */
function insertSearchBtn() {
	var numberText = /^[0-9]+$/
	appendNumberToPage()
	$("body").on(getEndClickEvent(), ".class-span-searchBtnTwo", function(){
		var pageNum = Number($(this).siblings(".class-input-pageNumberTwo").val())
		if (!pageNum || !numberText.test(pageNum)) {
			return
		}
		//
		var $parent = $(this).parents(".tableinfo")
		if ($parent.length == 0) {
			$parent = $(this).parents(".ordertableInfo") 
		}
		$parent.siblings(".class-tableDataTable").DataTable().page(pageNum - 1).draw(false)
	});		
}

/*	真分页根据输入页数跳转到指定页 */
function truePageSearchBtn() {
	var numberText = /^[0-9]+$/
	appendNumberToPage()
	$("body").on("click",".class-span-searchBtnTwo", function(){
		var pageNum =$(this).siblings(".class-input-pageNumberTwo").val()
		console.log(11111111111111111,pageNum)
		if (!pageNum || !numberText.test(pageNum)) {
			return
		}
		//
		$(this).parents(".dataTables_wrapper").find(".class-tableDataTable").DataTable().ajax.reload();
		/*var $parent = $(this).parents(".tableinfo")DataTable()
		if ($parent.length == 0) {
			$parent = $(this).parents(".ordertableInfo") 
		}
		$parent.siblings(".class-tableDataTable").DataTable().page(pageNum - 1).draw(false)*/
	});		
}


function getUserBalanceValue() {
	
}


function getSTRTime(date, letter) {
	var dateValue = date
	var y = dateValue.getFullYear()
	var m = dateValue.getMonth() + 1
	var d = dateValue.getDate()
	if (m < 10) {
		m = "0" + m
	}
	if (d < 10) {
		d = "0" + d
	}
	return y + letter + m + letter + d
}

var PASSWORD = "qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0123456789"
var checkPassWord = function(s2) {
	if (!s2) {
		return false
	}
	for (var j = 0; j < s2.length; j++) {
		var letter = s2[j]
		if (!PASSWORD.includes(letter)) {
			return false
		}
	}
	if (s2.length < 6 || s2.length > 16) {
		return false
	}
	return true
}	

function autoUpdateUserBalance(node,letter) {
	var $node = $(node)
	$.ajax({
		url: "/u/userMoney.do",
		type:"post",
		data:{},
		success:function(data){
			if (data["indexOf"] && data.indexOf("<!DOCTYPE html>") != -1) {
				window.location.reload()
				return
			}
			$node.text(letter + data.data)
		},
	})	
	/*setInterval(function() {
		$.ajax({
			url: "/u/userMoney.do",
			type:"post",
			data:{},
			success:function(data){
				if (data["indexOf"] && data.indexOf("<!DOCTYPE html>") != -1) {
					window.location.reload()
					return
				}				
				$node.text(letter + data.data)
			},
		})			
	}, 10000)*/
}
function compareStartTimeAndEndTime(startT, endT, callback) {
	if (startT === "" || endT === "") {
		callback()
		return
	}
	if (new Date(startT).getTime() > new Date(endT).getTime()) {
		showNoticeModal("开始时间大于结束时间")
		return
	}
	callback()
}

var noticeTemplateHTML = "<div class='div-c-noticeContentDiv animated bounceIn'>"+
			"<div class='noticeContentInner'>"+
				"<div class='title' style='background-color:#059BF3;'><span class='title'>__title__</span>"+
					"<div class='div-c-svgWrapper'>"+
	          			"<svg class='icon' aria-hidden='true' style='fill:white'>"+
				  	  "<use xlink:href='#icon-14CIRCLE'></use>"+
					"</svg>"+
					"</div>"+
				"</div>"+
				"<div class='main'>"+
				"<div class='content'>__content__</div>"+
				"<div class='extra'>__extra__</div>"+
				"</div>"+
			"</div>"+
		"</div>"
	

function showAlertNotice(title, content, extra) {
	var temp = noticeTemplateHTML.replace("__title__", title).replace("__content__", content).replace("__extra__", extra)
	$("body").append(temp)
	if(title=="抽奖说明"){
		$(".noticeContentInner .title").css("background-color","#d24c24")
		$(".noticeContentInner").css("border","2px solid #d24c24")
		$(".noticeContentInner .title").css("border-top","2px solid #d24c24")
		$(".noticeContentInner .title").css("border-bottom","1px solid #d24c24")
	}else{
		$(".noticeContentInner .title").css("background-color","#059BF3")
		$(".noticeContentInner").css("border","2px solid #059BF3")
		$(".noticeContentInner .title").css("border-top","2px solid #059BF3")
		$(".noticeContentInner .title").css("border-bottom","1px solid #059BF3")
	}
	$(".div-c-noticeContentDiv").on("click",".icon",function(){
		
		$(this).parents(".div-c-noticeContentDiv").removeClass("bounceIn").addClass("bounceOut");
		$(".div-c-noticeContentDiv").remove();
	})
	//$(node).addClass("div-c-noticeContentDiv-active")
}

var animationEnd = function(el) {
    var animations = {
      animation: 'animationend',
      OAnimation: 'oAnimationEnd',
      MozAnimation: 'mozAnimationEnd',
      WebkitAnimation: 'webkitAnimationEnd',
    };

    for (var t in animations) {
      if (el.style[t] !== undefined) {
        return animations[t];
      }
    }
}

window.addEventListener("load", function() {
	$("body").on("click", ".hasmaxwidth-td", function(e) {
		var titleValue = $(e.currentTarget).html()
		showNoticeModal(titleValue)
	})
	$("body").on(getEndClickEvent(), ".div-c-svgWrapper", function(event) {
		var $parentDiv = $(event.currentTarget).closest(".div-c-noticeContentDiv")
		$parentDiv.removeClass("bounceIn").addClass("bounceOut").one(animationEnd($parentDiv[0]), function(e) {
			$(e.currentTarget).remove()
		})
	})	
})	




function initEditor(node) {
	var E = window.wangEditor
	var editor = new E(node)
	editor.customConfig.uploadImgServer = '/activity/richTextPictureUpload.do'
		editor.customConfig.showLinkImg = false
	    editor.customConfig.colors = [
	                                  '#000000',
	                                  '#eeece0',
	                                  '#1c487f',
	                                  '#4d80bf',
	                                  '#c24f4a',
	                                  '#8baa4a',
	                                  '#7b5ba1',
	                                  '#46acc8',
	                                  '#f9963b',
	                                  '#ffffff',
	                                  '#f00',
	                              ]
		editor.customConfig.menus = [
		    'head',  // 标题
		    'link', //超链接
		    'bold',  // 粗体
		    'fontSize',  // 字号
		    'fontName',  // 字体
		    'italic',  // 斜体
		    'underline',  // 下划线
		    'strikeThrough',  // 删除线
		    'foreColor',  // 文字颜色
		    'backColor',  // 背景颜色
		    'justify',  // 对齐方式
		    'quote',  // 引用
		    'emoticon',  // 表情
		    'image',  // 插入图片
		    'table',  // 表格
		    'undo',  // 撤销
		    'redo'  // 重复
		]	
		editor.customConfig.uploadFileName = 'file'
		editor.create()		
}

function getAnimationEventName(el) {
	  var animations = {
	    animation: 'animationend',
	    OAnimation: 'oAnimationEnd',
	    MozAnimation: 'mozAnimationEnd',
	    WebkitAnimation: 'webkitAnimationEnd',
	  }

	  for (var t in animations) {
	    if (el.style[t] !== undefined) {
	      return animations[t];
	    }
	  }
}

//获取地址参数
function getUrlParam(name){
	var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)","i"); 
	var r =  window.location.search.substr(1).match(reg);
	var strValue = "";
	if (r!=null){
	 strValue= unescape(r[2]);
	}
	return strValue;
}

//动画弹窗提示(前提是页面有弹窗的html代码)
function BindNoticeContent(data){
	$(".div-c-noticeContentDiv .message-tip-body").text(data)
	$(".div-c-noticeContentDiv").removeClass("bounceOut").addClass("bounceIn").show() 
	setTimeout(function(){$(".div-c-noticeContentDiv").removeClass("bounceIn").addClass("bounceOut")},1000); 
}
//iframe子页面触发父页面动画弹窗提示(前提是父页面有弹窗的html代码)
function IframeNoticeContent(data){
	window.parent.$(".div-c-noticeContentDiv .message-tip-body").text(data)
	window.parent.$(".div-c-noticeContentDiv").removeClass("bounceOut").addClass("bounceIn").show() 
	setTimeout(function(){window.parent.$(".div-c-noticeContentDiv").removeClass("bounceIn").addClass("bounceOut")},1000);
}


//			=====================Layer框架的弹窗使用=====================
function bindLayerControl(title,content,x,y){   //信息弹出框(自己设定宽高)  
	layer.open({
	    type: 1,
	    title:title,
	    area: [x,y],
	    anim: 4,
	    shadeClose: true, //点击遮罩关闭
	    content: content,
	    btn:'朕知道了',
	  });
}

function bindLayerLittle(title,content){   //信息弹出框(小弹窗)  
	layer.open({
	    type: 1,
	    area:['300px',"200px"],
	    title:title,
	    shadeClose: true, //点击遮罩关闭
	    anim: 4,
	    content: content,    //右边也可以自己定义样式，引用时最外面的那个id,如$("#"+"ID名")
	    btn:'知道了',
	  });
}

function PrentLayerLittle(title,content){   //父窗口信息弹出框(小弹窗)  
	top.layer.open({
	    type: 1,
	    area:['300px',"200px"],
	    title:title,
	    shadeClose: true, //点击遮罩关闭
	    anim: 2,
	    content: content,    //右边也可以自己定义样式，引用时最外面的那个id,如$("#"+"ID名")
	    btn:'知道了',
	  });
}

function goToLoginLayer(title,content){   //提示没有登录，跳转到首页的弹窗
	layer.open({	
	    type: 1,
	    area:['300px',"200px"],
	    title:title,
	    shadeClose: false, //点击遮罩关闭
	    anim: 4,
	    content: content,    //右边也可以自己定义样式，引用时最外面的那个id,如$("#"+"ID名")
	    btn:'知道了',
	    yes:function(layero,index){
	    	window.location.href="/pc/index.do";
	    }
	  });
}


function bindLayerBig(title,content){   //信息弹出框(大弹窗)  
	layer.open({
	    type: 1,
	    area:['50%',"50%"],
	    title:title,
	    shadeClose: true, //点击遮罩关闭
	    content: content,
	    btn:'知道了',   // 双按钮的话["",""]	
	  });
}

/*function bindSoftkeyborard(document,document1){     //解决IOS input软键盘错位的问题(类名)
$(slector).bind("focus",function(){
		   $(slector1).css({"position":"static","bottom":0});staticabsolute
		}).bind("blur",function(){
		  $(slector1).css("position","fixed");
		});
	
}*/

/*function WindowHeightChange(){  //监听窗口发生变化时(只能监听Android手机)
	
	var windheight = $(window).height();//未唤起键盘时当前窗口高度
	$(window).resize(function(){   //当浏览器高度发生变化时
		if(windowChange){
			var docheight = $(window).height();//唤起键盘时当前窗口高度
			if(docheight < windheight){//当唤起键盘高度小于未唤起键盘高度时执行
			$(".top").css("position","static");
			$(".foot").hide();
			$(".foot").css("position","static");
			}else{
			$(".top").css("position","fixed");
			$(".foot").show();
			$(".foot").css("positioffn","fixed");
			}
		}
	});
}*/

/*var bfscrolltop = document.body.scrollTop;
function bindChatBar(){
	$(".div-c-editArea").focus(function(){
	     interval = setInterval(function(){
	     document.body.scrollTop = document.body.scrollHeight;
	     },100)
	 }).blur(function(){
	     clearInterval(interval);
	     document.body.scrollTop = bfscrolltop;
	 });
}*/


function isIOS(){
	var u = navigator.userAgent;
	var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
	return isiOS;
}
function Baccarat(zhuang1,zhuang2,zhuangBuBrand,xian1,xian2,leisureCard,tableNumber,issueNumber){
	var	arbitraryPairs = -1; //任意对子 0-没有任意对子  1有任意对子',
	var perfectPair = -1; //'完美对子 0-没有完美对子   1-有完美对子',
	var	size = -1; // '0-小   1-大',
	var zhuangPairs = -1; //庄对 0-没有庄对 1-有庄对
	var idleTime = -1; //闲对 0-没有闲对 1-有闲对
	var winner = -1; //开奖状态  0-闲家赢 1-庄家赢  2-和局
	var leisureHomePoints = -1;//闲家最终点数
	var makerSFinalPoints = -1; //庄家最终点数
	var frontPointsofIdleReplacementCards = -1; //闲家补牌前点数
	var frontPointsOfZhuangshi = -1;//庄家补牌前点数
	var leisureCards = "" ;//闲家补牌
	var leisures2 = ""; //闲家第二张牌
	var leisures1 = "" ;//闲家第一张牌
	var dealerCards = ""; //庄家补牌
	var zhuangs2 = "" ; //庄家开奖第二张牌
	var zhuangs1 = "" ;  //庄家开奖第一张牌
	
	var zd;//庄家的点数
	var xd;//闲家的点数

	var x1 = xian1.split(",");//闲家第一张牌
	var x2 = xian2.split(",");//闲家第二张牌
	var  xbp = ""; //闲家补牌
	
	var z1 = zhuang1.split(",");//庄家的第一张牌
	var z2 = zhuang2.split(",");//庄家的第二张牌
	var zbp = "";//庄家不牌
	//闲家判断
	if(x1[1] != "j" && x1[1] != "q" && x1[1] != "k" && x1[1] != "a"){
		xd=parseInt(x1[1])
	}else if(x1[1] == "a"){
		xd=1
	}else{
		xd=0
	}
	if(x2[1] != "j" && x2[1] != "q" && x2[1] != "k" && x2[1] != "a"){
		xd+=parseInt(x2[1])
	}else if(x2[1] == "a"){
		xd+=1
	}
	if(xd >= 10){//当大于10去掉前面第一个数字
		if(xd != 11){
			xd  = parseInt(String(xd).replace("1",""))
		}else{
			xd = 1
		}
	}
	if(xd == 0 || xd == 1 || xd == 2 || xd == 3 || xd == 4 || xd == 5){//闲家需要补牌 
		if(leisureCard == ""){
			return "闲家需要补牌";
		}
	}
	if(xd == 6 || xd == 7 || xd == 8 || xd == 9){//闲家不需要补牌
		if(leisureCard != ""){
			return "闲家不需要补牌";
		}
	}
	frontPointsofIdleReplacementCards = xd;//闲家补牌前点数
	if(leisureCard != ""){//撇开闲家补牌
		xbp = leisureCard.split(",");
		if(xbp[1] != "j" && xbp[1] != "q" && xbp[1] != "k" && xbp[1] != "a"){
			xd+=parseInt(xbp[1])
		}else if(xbp[1] == "a"){
			xd+=1
		}
	}
	//庄家判断
	if(z1[1] != "j" && z1[1] != "q" && z1[1] != "k" && z1[1] != "a"){
		zd=parseInt(z1[1])
	}else if(z1[1] == "a"){
		zd=1
	}else{
		zd=0
	}
	if(z2[1] != "j" && z2[1] != "q" != z2[1] != "k" && z2[1] != "a"){
		zd = zd+parseInt(z2[1])
	}else if(z2[1] == "a"){
		zd+=1
	}
	if(zd >= 10){//当大于10去掉前面第一个数字
		if(zd != 11){
			zd = parseInt(String(zd).replace("1",""))
		}else{
			zd = 1
		}
	}
	if(zd == 0 || zd == 1 || zd == 2){//庄家需要补牌
		if(zhuangBuBrand == ""){
			return "庄家需要补牌";
		}
	}
	if(zd == 3){//当闲家补得第三张牌是8时 不需要补牌 其余补牌
		if(leisureCard == ""){
			//庄家需要补牌
			if(zhuangBuBrand == ""){
				return "庄家需要补牌";
			}
		}else{
			if(parseInt(xbp[1]) == 8){//当闲家补得第三张牌是8的时候
				if(zhuangBuBrand != ""){
					return "闲家补得第三张牌为8庄家不可以补牌";
				}
			}else{
				//需要补牌
				if(zhuangBuBrand == ""){
					return "庄家需要补牌";
				}
			}
		}
	}
	if(zd == 4){//当闲家补得第三张牌是0.1.8.9，不须补牌；其余则须补牌
		if(leisureCard == ""){
			//需要补牌
			if(zhuangBuBrand == ""){
				return "庄家需要补牌";
			}
		}else{
			if(parseInt(xbp[1]) == 0 || parseInt(xbp[1]) == 1 || parseInt(xbp[1]) == 8 || parseInt(xbp[1]) == 9){
				if(zhuangBuBrand != ""){
					return "闲家补得第三张牌为0或1或8或9庄家不可以补牌";
				}
			}else{
				//需要补牌
				if(zhuangBuBrand == ""){
					return "庄家需要补牌";
				}
			}
		}
	}
	if(zd == 5){//当闲家补得第三张牌是0.1.2.3.8.9，不须补牌；其余则须补牌
		if(leisureCard == ""){
			//需要补牌
			if(zhuangBuBrand == ""){
				return "庄家需要补牌";
			}
		}else{
			if(parseInt(xbp[1]) == 0 || parseInt(xbp[1]) == 1 || parseInt(xbp[1]) == 2 || parseInt(xbp[1]) == 3 || parseInt(xbp[1]) == 8 || parseInt(xbp[1]) == 9){
				//不需要补牌
				if(zhuangBuBrand != ""){
					return "闲家补得第三张牌为0或1或8或9庄家不可以补牌";
				}
			}else{
				//需要补牌
				if(zhuangBuBrand == ""){
					return "庄家需要补牌";
				}
			}
		}
	}
	if(zd == 6){//当闲家补得第三张牌是0.1.2.3.4.5.8.9，不须补牌；其余则须补牌
		if(leisureCard == ""){
			//需要补牌
			if(zhuangBuBrand == ""){
				return "庄家需要补牌";
			}
		}else{
			if(parseInt(xbp[1]) == 0 || parseInt(xbp[1]) == 1 || parseInt(xbp[1]) == 2 || parseInt(xbp[1]) == 3 || parseInt(xbp[1]) == 4 ||  parseInt(xbp[1]) == 5 || parseInt(xbp[1]) == 8 || parseInt(xbp[1]) == 9){
				//不需要补牌
				if(zhuangBuBrand != ""){
					return "闲家补得第三张牌为0或1或8或9庄家不可以补牌";
				}
			}else{
				//需要补牌
				if(zhuangBuBrand == ""){
					return "庄家需要补牌";
				}
			}
		}
	}
	if(zd == 7 || zd == 8 || zd == 9){
		//不需要补牌
		if(zhuangBuBrand != ""){
			return "庄家点数为7或8或9点不可以补牌";
		}
	}
	frontPointsOfZhuangshi = zd;//庄家补牌前点数
	if(zhuangBuBrand != ""){//抛开庄家补的牌
		zbp = zhuangBuBrand.split(",");
		if(zbp[1] != "j" && zbp[1] != "q" && zbp[1] != "k" && zbp[1] != "a"){
			zd+=parseInt(zbp[1])
		}else if(zbp[1] == "a"){
			zd+=1
		}
	}
	//以上是判断填写进来的值是否正确
	zhuangs1 = String(zhuang1).replace(",","");
	zhuangs2 = String(zhuang2).replace(",","");
	if(zhuangBuBrand != ""){
		dealerCards = String(zhuangBuBrand).replace(",","");
	}
	leisures1 = String(xian1).replace(",","");
	leisures2 = String(xian2).replace(",","");
	if(leisureCard != ""){
		leisureCards = String(leisureCard).replace(",","");
	}
	//判断大小
	if(zhuangBuBrand != "" || leisureCard != ""){
		size = 1;
	}else{
		size = 1
	}
	//判断是否有完美对子
	if(leisures1 == leisures2 || leisures1==leisureCards || leisures2==leisureCards 
	&& zhuangs1 == zhuangs2 || zhuangs1 == dealerCards ||  zhuangs2 == dealerCards
	){
		perfectPair = 1;
	}else{
		perfectPair = 0;
	}
	//判断是否有任意对子
	if(leisures1 == leisures2 || leisures1==leisureCards || leisures2==leisureCards 
		|| zhuangs1 == zhuangs2 || zhuangs1 == dealerCards ||  zhuangs2 == dealerCards){
		arbitraryPairs = 1;
	}else{
		arbitraryPairs = 0;
	}
	//判断是否有庄对
	if(zhuangs1 == zhuangs2 || zhuangs1 == dealerCards || zhuangs2 == dealerCards){
		zhuangPairs = 1;
	}else{
		zhuangPairs = 0;
	}
	//判断是否有闲对
	if(leisures1 == leisures2 || leisures1 == leisureCards || leisures2 == leisureCards){
		idleTime = 1;
	}else{
		idleTime = 0;
	}
	//判断赢家
	if(zd > xd){//开奖状态  0-闲家赢 1-庄家赢  2-和局
		//庄赢
		winner = 1;
	}else if(xd > zd){
		//闲赢
		winner = 0;
	}else if(zd == xd){
		//和局
		winner = 2;
	}
	leisureHomePoints = xd;//闲家最终点数
	makerSFinalPoints = zd;//庄家最终点数
	$.ajax({//将预设数据发送给服务器
		url:'/bjlhtgl/baccaratPresupposition.do',
		type:'post',
		data:{
			arbitraryPairs:arbitraryPairs, //任意对子 0-没有任意对子  1有任意对子',
			perfectPair: perfectPair,//'完美对子 0-没有完美对子   1-有完美对子',
			size: size,// '0-小   1-大',
			zhuangPairs: zhuangPairs,//庄对 0-没有庄对 1-有庄对
			idleTime: idleTime,//闲对 0-没有闲对 1-有闲对
			winner: winner, //开奖状态  0-闲家赢 1-庄家赢  2-和局
			leisureHomePoints:leisureHomePoints,//闲家最终点数
			makerSFinalPoints: makerSFinalPoints,//庄家最终点数
			frontPointsofIdleReplacementCards: frontPointsofIdleReplacementCards,//闲家补牌前点数
			frontPointsOfZhuangshi: frontPointsOfZhuangshi,//庄家补牌前点数
			leisureCard: leisureCards,//闲家补牌
			leisure2: leisures2,//闲家第二张牌
			leisure1: leisures1,//闲家第一张牌
			dealerCard: dealerCards,//庄家补牌
			zhuang2: zhuangs2,//庄家开奖第二张牌
			zhuang1: zhuangs1,  //庄家开奖第一张牌
			tableNumber: tableNumber,//开奖桌号
			issueNumber: issueNumber,//开奖期号
		},
		success:function(data){
			if(data.data == 1){
				return "恭喜你预设开奖数据成功";
			}
			return "很遗憾！你数据填写不对预设失败";
		}
	});
}

		function setMainTitle(page) {
		 	var urlPath = "/xfm.do"
			var newRequest = {
				url: urlPath,
				type: "post",
				data: {"page":page},
				success: function(data) {
					if(data==60){
						pagePreserve()
						return;
					}
					var newData = JSON.parse(data);
					if(newData.data=="nullnull" || newData.data=="" || newData.data==null){   //如果该页面还没存在或者为nullnull
						error.push(page)  //将该页面添加到维护数组中
							 maintenance() 
						return;
					}else{
						$("#xfm").empty();
						if(error.indexOf(page)!=-1){    //如果该页面存在了，判断维护数组，如果存在该页面则从维护数组中删除该页面
							removeByValue(error,page)
						}
						localStorage.setItem(page,newData.data)
						$("#xfm").append(newData.data) 
					}
					
				},
				error: function(status) {
				}
			}
			ajax(newRequest)			
		}
		//封装取页面数据的方法(取出数据)
		function bindSetData(page){
			if(page=="cZfanshui" || page=="zhuanpan" || page=="sy"){
				$(".foot").hide()
			}else{
				$(".foot").show()
			}
			var newData=localStorage.getItem(page)
			console.log(newData);
			if(newData == undefined || newData=="" || newData=="nullnull"){
				setMainTitle(page)
			}else{  
				$("#xfm").html("")  
				 $("#xfm").html(newData)
			}
			bindAllCloseFakeModalBtns()
		}
		
		function bindAllData(page){
			if(localStorage.getItem(page)==undefined || localStorage.getItem(page)=="" || localStorage.getItem(page)=="nullnull" ){
					$.ajax({
						url: "/xfm.do",
						type: "post",
						data: {"page":page},
						success: function(data) {
							if(data==60){
								pagePreserve()
								return;
							}
							if(error.indexOf(page)!=-1){
								removeByValue(error, page)
							}
							 localStorage.setItem(page,data.data)
						},
						error: function(status) {
							error.push(page)
							console.log(error)
						}
					})
			}
		}
		
		//终极拿单个彩种的方法
		function bindsetLotterData(lottercname){
			var newData=localStorage.getItem(lottercname)
			//console.log(newData)
			if(newData==undefined || newData=="" || newData=="nullnull"){  //没有提前储存的话要掉接口去拿一遍
				bindoneLotterData(lottercname)
			}else{   //直接显示
				$("#xfm").empty();
				$("#xfm").append(newData)
			}
		}
		
		//封装拿每个下注页面数据的方法
		function bindoneLotterData(lottercname){
			 $.ajax({ 
					url:'/lotter/lot.do', 
					type:'post', 
					data:{cname:lottercname}, 
					success:function(data){ 
						if(data==60){
							pagePreserve()
							return;
						}
						var newData=data.data;
						newData=newData.trim();
						if(newData=="nullnull" || newData=="" || newData==null){   //如果该页面还没存在或者为nullnull
							return;
						}else{
							if(error.indexOf(lottercname)!=-1){    //如果该页面存在了，判断维护数组，如果存在该页面则从维护数组中删除该页面
								removeByValue(error,lottercname)
							}
							localStorage.setItem(lottercname,newData)
							$("#xfm").empty(); 
							$("#xfm").append(newData) 
						}
					},
				}) 
		}
			
			//封装提前储存好需要存储的彩种页面数据
			function bindAllLotterData(lottercname){
				if(localStorage.getItem(lottercname)==undefined || localStorage.getItem(lottercname)=="" || localStorage.getItem(lottercname)=="nullnull"){
					$.ajax({ 
						url:'/lotter/lot.do', 
						type:'post', 
						data:{cname:lottercname}, 
						success:function(data){ 
							if(data==60){
								pagePreserve()
								return;
							}
							var newData=data.data;
							localStorage.setItem(lottercname,newData)
						},
						complete: function(xhr) {
							if(xhr.status == 1314520){
								if(save[save.length-1]!="sy"){
									save.push("sy")
								}
								bindSetData("login")
							}
						} 
					})	
				}
			}
			
			function GotoLogin(){
				layer.open({
				    type: 1,
				    area:['300px',"150px"],
				    title:'温馨提示',
				    shadeClose: true, //点击遮罩关闭
				    anim: 4,
				    content: '请先登录',    //右边也可以自己定义样式，引用时最外面的那个id,如$("#"+"ID名")
				    btn:'知道了',
				    yes: function(index, layero){
				    	layer.close(layer.index)
				    	save.push('sy')
				    	bindSetData('login')
				    }
				  });
		}
		
		function maintenance(){   //页面报错，提示维护
			layer.open({
			    type: 1,
			    area:['300px',"150px"],
			    title:'温馨提示',
			    shadeClose: true, //点击遮罩关闭
			    anim: 4,
			    content: '该页面正在维护中...请稍后再试',    //右边也可以自己定义样式，引用时最外面的那个id,如$("#"+"ID名")
			    btn:'知道了',
			  });
		}
		
 		
		function firstLoadData(){  //一开始进入页面加载的数据
			    bindAllData("sy")
				bindAllData("gc") 
				bindAllData("kj")
				bindAllData("zs")
				bindAllData("wd")
				bindAllData("login")
				bindAllData("zhuce")
				bindAllLotterData("2fssc")
				bindAllLotterData("shssl")
				bindAllLotterData("3fk3")
				/*bindAllData("kaijiangJl")   //暂时注释掉 提高用户访问效率  后期可能会用
				bindAllData("tryplay")
				bindAllLotterData("2fpk10")
				bindAllLotterData("bjpk10")
				bindAllLotterData("3fk3")
				bindAllLotterData("bjk3")
				bindAllLotterData("5f6hc")
				bindAllLotterData("gdkl10f")
				bindAllLotterData("ah11x5")
				bindAllLotterData("gd11x5")
				bindAllLotterData("sd11x5")
			  	bindAllLotterData("jsk3")*/
		}
		
		function userLoginData(){  //点击登录或则注册成功的时候需要加载的数据
			bindAllLotterData("gxk3")
	 		/*bindAllData("chongzhi") //暂时注释掉 提高用户访问效率  后期可能会用
			bindAllData("zhuanpan")
			bindAllData("yHactivity")
			bindAllData("yHactivityDetail")
			bindAllData("onLineJL")
			bindAllData("contactKF")
			bindAllData("xiazhuJl")
			bindAllData("agent")
			bindAllData("zhanghuLs")
			bindAllData("bankMessage")
			bindAllData("cZfanshui")
			bindAllData("qiandao")
			bindAllData("systemNotice")
			bindAllData("damaTj")
			bindAllData("dailiExplain")
			bindAllData("userManage")
			bindAllData("dailiCommission")
			bindAllData("reportStatistic")
			bindAllLotterData("xyft")
			bindAllLotterData("xysm")
		  	bindAllLotterData("cqssc")
		  	bindAllLotterData("tjssc")
			bindAllLotterData("cqkl10f")
		  	bindAllLotterData("jx11x5")
		  	bindAllLotterData("sh11x5")
		  	bindAllLotterData("ahk3")
		  	bindAllLotterData("fc3d")
			bindAllLotterData("bj28")
		  	bindAllLotterData("xy28")
		  	bindAllLotterData("jnd28") 
		  	bindAllLotterData("xjssc") 
		  	bindAllLotterData("bjl") 
		  	bindAllLotterData("xg6hc")*/
		}
		
		
		//页面进入维护状态
		function ErrorState(data){
			if(data==60){
				bindSetData("sy")
			}
		}
		
		//根据AddDayCount的值获取到当天的日期
		 function GetDateStr(AddDayCount) { 
			    var dd = new Date(); 
			        dd.setDate(dd.getDate()-AddDayCount);/*  获取AddDayCount天前的日期 */
			        var y = dd.getFullYear(); 
			        var m = dd.getMonth()+1;/*  获取当前月份的日期 */
			        if(m<10){
			        	m="0"+m;
			        }
			        var d = dd.getDate();
			        if(d<10){
			        	d="0"+d;
			        }
			        return y+"-"+m+"-"+d; 
			} 
		 
		 
		//根据AddMonthCount的值获取到当月日期
		 function GetMonthStr(AddMonthCount) { 
		    var dd = new Date(); 
		        dd.setMonth(dd.getMonth()-AddMonthCount);/*  获取AddDayCount天前的日期 */
		        var y = dd.getFullYear(); 
		        var m = dd.getMonth()+1;/*  获取当前月份的日期 */
		        if(m<10){
		        	m="0"+m;
		        }
		        var d = dd.getMonth();
		        if(d<10){
		        	d="0"+d;
		        }
		        return y+"-"+m; 
		} 

